#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    // 设置窗口的最大尺寸
    setMaximumSize(400, 300);

    // 设置窗口的最小尺寸
    setMinimumSize(200, 150);

    // 设置窗口的固定大小

    // 设置窗口标题
    setWindowTitle("Hello Qt!");

    // 设置窗口的图标(设置的图标像素太大Qt会显示不出来)
    setWindowIcon(QIcon("D:\\Wallparper\\Min_Qt.png"));

    connect(ui->push_button_01, &QPushButton::clicked, this, [=]() {
        QRect rect = this->frameGeometry();
        move(rect.topLeft() + QPoint(400, 0));
    });

    connect(ui->push_button_02, &QPushButton::clicked, this, [=]() {
        QRect rect = this->frameGeometry();

        qDebug() << "左上角:" << rect.topLeft()
                 << " 右上角:" << rect.topRight()
                 << " 左下角:" << rect.bottomLeft()
                 << " 右下角:" << rect.bottomRight()
                 << " 宽度:" << rect.width()
                 << " 高度:" << rect.height() << endl;
    });

    connect(ui->push_button_03, &QPushButton::clicked, this, [=]() {
        QRect rect = this->frameGeometry();

        int x = rect.x() - 300;
        int y = rect.y();
        int width = rect.width() - 100;
        int height = rect.height() - 50;

        this->setGeometry(x, y, width, height);
    });

    // 连接鼠标右键事件(有BUG!!!)
    connect(this, &QMainWindow::customContextMenuRequested, this, [=](const QPoint &pos) {
        QMenu menu;

        menu.addAction("Add File");
        menu.addAction("Delete File");
        menu.addAction("Close");

        menu.exec(QCursor::pos());
    });
}

Widget::~Widget()
{
    delete ui;
}

